package com.broadengate.init;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;
import java.util.Properties;

import org.apache.log4j.Logger;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.annotation.Autowired;

import com.broadengate.bean.DepartmentInfo;
import com.broadengate.service.DepartmentService;
import com.broadengate.view.controller.LoginController;

public class IsmpInit
{
    private final static Logger log = Logger.getLogger(LoginController.class);
    
    private static Properties excelProperties;
    
    private static List<DepartmentInfo> departmentInfo;
    
    @Autowired
    private DepartmentService departmentService;
    
    public void init() throws BeansException
    {
        log.info("初始化ISMP系统相关配置");
        log.info("初始化excel导入字段配置");
        InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream("excelupload.properties");
        Properties p = new Properties();
        try
        {
            p.load(inputStream);
        }
        catch (IOException e1)
        {
            log.error("初始化加载配置文件失败", e1);
        }
        
        log.info("初始化部门信息");
        
        departmentInfo = departmentService.getDepartmentById(0);
        
        log.info("加载配置文件完成" + p.toString());
        excelProperties = p;
    }
    
    public static Properties getProperties()
    {
        return excelProperties;
    }

    public static List<DepartmentInfo> getDepartmentInfo()
    {
        return departmentInfo;
    }

    public static void setDepartmentInfo(List<DepartmentInfo> departmentInfo)
    {
        IsmpInit.departmentInfo = departmentInfo;
    }
    
    
}
